package com.glorysoft.hlgdpda.ui.materialandtool.view

import android.os.Bundle
import androidx.databinding.ViewDataBinding
import com.glorysoft.hlgdpda.BR
import com.glorysoft.hlgdpda.R
import com.glorysoft.hlgdpda.base.BaseActivity
import com.glorysoft.hlgdpda.base.BaseViewModel
import com.glorysoft.hlgdpda.databinding.ActivityBatchBindCarrierBinding
import com.glorysoft.hlgdpda.entity.ui.ToastMessageBean
import com.glorysoft.hlgdpda.ui.materialandtool.viewmodel.BatchBindCarrierViewModel
import kotlinx.android.synthetic.main.activity_batch_bind_carrier.*

/**
 * FileName: BatchBindCarrierActivity
 * Author: XJH
 * Date: 2021/11/10 15:37
 * Description:
 * History:
 */
class BatchBindCarrierActivity : BaseActivity<BatchBindCarrierViewModel,ActivityBatchBindCarrierBinding>() {
    override fun layoutId(): Int {
        return R.layout.activity_batch_bind_carrier
    }

    override fun initVariableId(): Int {
        return BR.batchBindCarrierViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle("批量绑定载具")
        rvUpMaterialList.setEmptyView(upMaterialEmptyView)
        setRightListener("提交"){
            viewModel.checkData()
        }

        initEdit(etBatchID,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchBatchInfo(s)
            }

        })

        initEdit(etLot,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchLotInfo(s)
            }

        })
    }

    override fun initData() {
        viewModel.defUI.callObserve.observe(this){
            when(it.type){
                210 ->{
                    tvNumber.text = it.item.toString()
                    etBatchID.setText("")
                    etLot.setText("")
                }
                200 ->{
                    if (it.item.toString().isEmpty()){
                        viewModel.defUI.toastEvent.value = ToastMessageBean("绑定成功",true)
                        finish()
                    }else{
                        viewModel.defUI.toastEvent.value = ToastMessageBean(it.item.toString() + "绑定失败",false)
                    }
                }
            }
        }
    }
}